package com.yj.web.dao.mapper;

import com.yj.web.dao.po.admin.HelpDoc;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by yanlinyang on 2017/7/24.
 */
@Component
public interface HelpDocMapper {
    @Select("select * from cus_helpDoc where deleted_flag = 'N' order by position asc, created_at desc limit #{size} offset #{offset}")
    public List<HelpDoc> listHelpDoc(@Param("offset") int offset, @Param("size") int size);

    @Select("select count(*) from cus_helpDoc where deleted_flag = 'N'")
    public int countHelpDoc();

    @Delete("update cus_helpDoc set deleted_flag = 'Y' where id = #{id} and deleted_flag = 'N'")
    public int deleteHelpDocById(@Param("id") int id);

    @Insert("insert into cus_helpDoc (create_id, created_at, content, title, link_url, position, status) " +
            "values (#{helpDoc.create_id}, now(), #{helpDoc.content}, #{helpDoc.title}, #{helpDoc.link_url}, #{helpDoc.position}," +
            "#{helpDoc.status})")
    @Options(useGeneratedKeys = true, keyProperty = "helpDoc.id")
    public long insertHelpDoc(@Param("helpDoc") HelpDoc helpDoc);

    @Update("update cus_helpDoc set update_id=#{helpDoc.update_id}, updated_at=now(), content=#{helpDoc.content}, title=#{helpDoc.title}, " +
            "link_url=#{helpDoc.link_url}, position=#{helpDoc.position}, status=#{helpDoc.status} where id = #{helpDoc.id} and deleted_flag = 'N'")
    public boolean updateHelpDoc(@Param("helpDoc") HelpDoc helpDoc);

    @Select("select * from cus_helpDoc where id = #{id} and deleted_flag = 'N'")
    public HelpDoc findHelpDocById(@Param("id") int id);

    @Update("update cus_helpDoc set status=#{status} where id = #{id}")
    public boolean updateHelpDocStatus(@Param("id") int id, @Param("status") int status);
}
